<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/WEB-INF/jsps/tag.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>智能财务管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <%@ include file="/WEB-INF/jsps/common_js.jsp" %>
    <%@ include file="/WEB-INF/jsps/common_css.jsp" %>
    <script type="text/javascript" src="${baseurl}static/js/login.js"></script>
    <link href="${baseurl}static/styles/login2.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<div id="w" class="easyui-window" title="${sysconfig_info.title}"
     data-options="modal:true,collapsible:false,closed:false,iconCls:'Lockgo',closable:false,minimizable:false,maximizable:false,top:150"
     style="width:400px;padding:20px 70px 20px 70px;">

    <div style="margin-bottom:10px">
        <input class="easyui-textbox" id="username" style="width:100%;height:30px;padding:12px"
               data-options="prompt:'登录用户名',iconCls:'icon-man',iconWidth:38">
    </div>
    <div style="margin-bottom:20px">
        <input class="easyui-textbox" id="password" type="password" style="width:100%;height:30px;padding:12px"
               data-options="prompt:'登录密码',iconCls:'icon-lock',iconWidth:38">
    </div>
    <div style="margin-bottom:20px">
        <input class="easyui-textbox" type="text" id="randomcode" style="width:50%;height:30px;padding:12px" data-options="prompt:'验证码'">
        <a href="javascript:;" class="showcode">
            <img id="validatecodeImgId" style=" margin:0 0 0 3px ; vertical-align:middle; height:26px;" src="/validatecode">
        </a>
    </div>
    <div style="margin-bottom:20px">
        <input type="checkbox" checked="checked" id="logrem">
        <span>Remember me</span>
    </div>
    <div>
        <a id="submit_buttono_id" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
           style="padding:5px 0px;width:100%;">
            <span style="font-size:14px;">登录</span>
        </a>
    </div>
</div>

<script type="application/javascript">

    //提交表单
    function submitForm() {
        var username = $("#username").val();
        var password = $("#password").val();
        var randomcode = $("#randomcode").val();

        if (!(username && password && randomcode)) {
            alert("请完善登陆信息.");
            return;
        }

        var postData = {
            username: username,
            password: password,
            randomcode: randomcode
        }

        $.ajax({
            type: "POST",
            url: "${baseurl}user/login",
            data: postData,
            success: function (data) {
                data = JSON.parse(data);
                if (data.success) {
                    window.location.href = "${baseurl}index";
                } else {
                    alert(data.content);
                    window.location.href = window.location.href;
                }
            }
        });
    }

    $(function () {
        //提交表单
        $("#submit_buttono_id").click(function () {
            submitForm();
        });

        //点击刷新验证码
        $("#validatecodeImgId").click(function () {
            $(this).attr("src", "${baseurl}validatecode?date=" + new Date());
        });

        //回车提交表单
        $(document).keydown(function(e) {
            if (e.keyCode == 13) {
                submitForm();
            }
        });
    });

</script>
</body>
</html>